package com.woniuxy.service.impl;

import com.woniuxy.entity.TakeawayMan;
import com.woniuxy.mapper.TakeawayManMapper;
import com.woniuxy.service.TakeawayManService;
import com.woniuxy.util.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @BelongsProject: pigTrotterStore
 * @BelongsPackage: com.woniuxy.service
 * @Author: Quan
 * @Date: 2025/3/18 21:09
 */
@Service
@AllArgsConstructor
public class TakeawayManServiceImpl implements TakeawayManService {
	private TakeawayManMapper takeawayManMapper;
	
	/**
	 * @Description: 根据条件查询外卖员
	 * @Param: [nameOrPhone]
	 * @return: java.util.List<com.woniuxy.entity.TakeawayMan>
	 * @Author: Quan
	 * @Date: 2025/3/18
	 * 1、根据名称进行查询，查询出来就直接返回
	 * 2、查询不出来：根据手机号进行查询
	 */
	@Override
	public ResponseData<?> queryInfo(String nameOrPhone) {
		List<TakeawayMan> takeawayMENByName = takeawayManMapper.queryInfoByName(nameOrPhone);
		List<TakeawayMan> takeawayMENByPhone = takeawayManMapper.queryInfoByPhone(nameOrPhone);
		ArrayList<TakeawayMan> collect = Stream.concat(takeawayMENByName.stream(), takeawayMENByPhone.stream())
				.collect(Collectors.toCollection(ArrayList::new));

		return ResponseData.ok(collect);
	}

	/**
	 * @Description: 查询全部
	 * @Param: []
	 * @return: java.util.List<com.woniuxy.entity.TakeawayMan>
	 * @Author: Quan
	 * @Date: 2025/3/18
	 */
	@Override
	public ResponseData<?> queryAll() {
		return ResponseData.ok(takeawayManMapper.queryAll());
	}
}
